home *** CD-ROM | disk | FTP | other *** search
- #!/usr/bin/perl5
- #
- # modem-accounts.cgi
- #
- # Copyright 1988-1996 Silicon Graphics, Inc.
- # All rights reserved.
- #
- # This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- # the contents of this file may not be disclosed to third parties, copied or
- # duplicated in any form, in whole or in part, without the prior written
- # permission of Silicon Graphics, Inc.
- #
- # RESTRICTED RIGHTS LEGEND:
- # Use, duplication or disclosure by the Government is subject to restrictions
- # as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- # and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- # successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- # rights reserved under the Copyright Laws of the United States.
- #
- # $Id: modem-account.frm,v 1.40 1997/06/19 22:25:59 shotes Exp $
-
- require "/usr/OnRamp/lib/OnRamp.pm";
- require "/usr/OnRamp/lib/java.pm";
-
- $conf = "/etc/uucp/Systems";
- $dummy = "/etc/uucp/Systems.temp";
- $myname = "modem-account.cgi";
- $title = "Modem Accounts";
-
- $js_main = "
- type = \"account\";
- $js_account_main
- $js_error_box
- $js_meta
- function testAdd(form) {
- if (!testMeta(form.nme, \"account name\")) return (false);
- return (true);
- }";
-
- $js_add =
- "$js_account_add
- $js_error_box
- $js_phone
- $js_meta
- function testAdd(form) {
- if (!testPhone(form.phone)) return (false);
- if (!testMeta(form.login,\"login name\")) return (false);
- if (!testMeta(form.password,\"login password\")) return (false);
- return (true);
- }";
-
-
- $js_edit =
- "$js_account_edit
- $js_error_box
- $js_phone
- $js_meta
- function testEdit(form) {
- if (!testMeta(form.nme,\"remote host name\")) return (false);
- if (!testPhone(form.phone)) return (false);
- if (!testMeta(form.login,\"login name\")) return (false);
- if (!testMeta(form.password,\"password\")) return (false);
- return (true);
- }";
-
- print "Content-type: text/html\n\n";
-
- &get_fields;
-
- &getAccounts;
-
- if (%fld) {
- $help = $document_root . $ENV{"SCRIPT_NAME"};
- $help =~ s/cgi$/hlp/;
- exec $help if ($fld{'help'} eq "Help");
-
- $fld{'phone'} =~ s/-//g;
- $fld{'phone'} =~ s/\(//g;
- $fld{'phone'} =~ s/\)//g;
- $fld{'phone'} =~ s/,//g;
- $fld{'chosen'} =~ /([\w.-]+)/;
- $fld{'chosen'} = $1;
- }
-
- if ($fld{'add'}) {
- &formValid_add;
- $val{'nme'} = $fld{'nme'};
- &addAccount;
- }
- elsif ($fld{'delete'}) {
- &error(2,"To delete an existing account, first select an account from
- list, then click the delete button.") if !$fld{'chosen'};
- $message = qq|Click "Ok" to save changes.|;
- &generic($fld{'chosen'});
- }
- elsif ($fld{'edit'}) {
- &error(2,"To edit an existing account, first select an account from
- list, then click the edit button.") if !$fld{'chosen'};
- &putEdit;
- &editAccount;
- }
- elsif ($fld{'doedit'}) { &formValid_doedit; &doEdit; &getAccounts; &generic; }
- elsif ($fld{'doit'}) {
- &tryToDelete;
- &getAccounts;
- if (!$message) { $message = "No changes made."; }
- &generic;
- }
- elsif ($fld{'doadd'}) { &formValid_doadd; &doAdd; &getAccounts; &generic; }
- else {
- if (%fld) { $val{'nme'} = $fld{'nme'}; $message = qq|Use buttons to submit form.|; }
- &generic;
- }
-
- sub formValid_add {
- &error(2,"Account name required.") if !$fld{'nme'};
- &error(2,"Invalid account name.") if &deluxeError($fld{'nme'});
- }
-
- sub formValid_doadd {
- &error(0,"Invalid phone number.") if !$fld{'phone'} || &check_phone($fld{'phone'});
- &error(0,"Invalid login name.") if &deluxeError($fld{'login'});
- &error(0,"Invalid password.") if &deluxeError($fld{'password'});
- }
-
-
- sub formValid_doedit {
- &error(1,"Invalid remote host name.") if &deluxeError($fld{'nme'});
- &error(1,"Invalid phone number.") if !$fld{'phone'} || &check_phone($fld{'phone'});
- &error(1,"Invalid login name.") if &deluxeError($fld{'login'});
- &error(1,"Invalid password.") if &deluxeError($fld{'password'});
- }
-
- sub deluxeError {
- return 1 if length($_[0]) > 8;
- return 1 if $_[0] =~ /$METACHARS/o;
- return 1 if $_[0] =~ /\s/;
- 0;
- }
-
- sub error {
- &error_block($_[1]);
- %val = %fld;
- if ($_[0] == 0) { &addAccount; }
- elsif ($_[0] == 1) { &editAccount; }
- else { &generic; }
- exit 0;
- }
-
- sub doEdit {
- open(IN,"< $conf");
- open(OUT,"> $dummy");
- $found = 0;
- while(<IN>) {
- $line = $_;
- if ($line =~ /^\s*\#/) { print OUT $line; next; }
- $line =~ /^\s*(.*)$/;
- $line1 = $1;
- @items = split(/\s+/,$line1);
- if ($items[2] eq "ACU" && $items[0] eq $fld{'chosen'}) {
- print OUT "# $line";
- if ($found == 0) {
- $found = 1;
- print OUT "$fld{'nme'} Any ACU $fld{'speed'} $fld{'phone'}";
- print OUT " in:--in: $fld{'login'}";
- if ($fld{'password'}) { print OUT " word: $fld{'password'}"; }
- print OUT "\n";
- }
- } else { print OUT $line; }
- }
- if ($found == 0) {
- print OUT "$fld{'nme'} Any ACU $fld{'speed'} $fld{'phone'}";
- print OUT " in:--in: $fld{'login'}";
- if ($fld{'password'}) { print OUT " word: $fld{'password'}"; }
- print OUT "\n";
- }
- close(IN);
- close(OUT);
- chmod 0600, $conf;
- rename($dummy,$conf);
- chmod 0400, $conf;
-
- $message = "Account edited.";
- }
-
- sub clear {
- open(OUT_0,"> $_[0]");
- close(OUT_0);
- }
-
- sub putEdit {
- $num = -1;
- for ($i=0;$i<$number;$i++) {
- if ($nme[$i] eq $fld{'chosen'}) { $num = $i; }
- }
-
- $val{'nme'} = $nme[$num];
- $val{'phone'} = $phone[$num];
- $val{'login'} = $login[$num];
- $val{'password'} = $password[$num];
- $val{'speed'} = $speed[$num];
- }
-
- sub editAccount {
- &js_title_block($title, $js_edit);
- &header_block("Edit Modem Account");
-
- print "<form name=EditForm action=$myname method=post onSubmit=\"return runSubmit()\">";
-
- print qq|<input type=hidden name="chosen" value=$fld{'chosen'}>|;
-
- print "<center><table cellpadding=5 width=450>";
-
- print "<tr><th align=left>Remote host name:</th><th align=left>",
- &text('nme',$val{'nme'}, 20),"</th></tr>";
-
- print "<tr><th align=left>Phone number:</th><th align=left>",
- &text('phone',$val{'phone'}, 20),"</th></tr>";
-
- print "<tr><th align=left>Login name:</th><th align=left>",
- &text('login',$val{'login'}, 20),"</th></tr>";
-
- print "<tr><th align=left>Password:</th><th align=left>",
- &text('password',"$val{'password'}", 20),"</th></tr>";
-
- print "<tr><th align=left>Baud rate:</th><th align=left>",
- &select('speed',$val{'speed'},
- '2400','9600','14400','19200','28800', '38400'),"</th></tr>";
-
- print "</table></center><br>";
-
- print &js_buttons('doedit','Ok','onClick="markEdit()"','onClick="markOther()"');
-
- print "</form></body></html>";
- }
-
- sub tryToDelete {
- $account = $fld{'toDelete'};
- if (!$account) { return 0; }
-
- open(IN,"< $conf");
- open(OUT,"> $dummy");
- while(<IN>) {
- $line = $_;
- if ($line =~ /^\s*\#/) { print OUT $line; next; }
- $line =~ /^\s*(.*)$/;
- $line1 = $1;
- @items = split(/\s+/,$line1);
- if ($items[2] eq "ACU" && $items[0] eq $account) {
- print OUT "# $line";
- } else { print OUT $line; }
- }
- close(IN);
- close(OUT);
- chmod 0600, $conf;
- rename($dummy,$conf);
- chmod 0400, $conf;
-
- $message = "Account deleted.";
- }
-
- sub doAdd {
- chmod 0600, $conf;
- open(OUT,">> $conf");
- print OUT "$fld{'nme'} Any ACU $fld{'speed'} $fld{'phone'} in:--in:";
- print OUT " $fld{'login'}";
- if ($fld{'password'}) { print OUT " word: $fld{'password'}"; }
- print OUT "\n";
- close(OUT);
- chmod 0400, $conf;
-
- $message = "New account added.";
- }
-
- sub addAccount {
- &js_title_block($title, $js_add);
- &header_block("Add New Modem Account");
-
- print "<form name=AddForm action=$myname method=post onSubmit=\"return runSubmit()\">\n";
-
- print "<center><table cellpadding=5 width=450>\n";
-
- print "<input type=hidden name=nme value=$val{'nme'}>\n";
-
- print "<tr><th align=left>Remote host name:</th><td><tt>",
- $val{'nme'},"</tt></td></tr>\n";
-
- print "<tr><th align=left>Phone number:</th><th align=left>",
- &text('phone',"$val{'phone'}",20),"</th></tr>\n";
-
- print "<tr><th align=left>Login name:</th><th align=left>",
- &text('login',"$val{'login'}",20),"</th></tr>\n";
-
- print "<tr><th align=left>Password:</th><th align=left>",
- &text('password',"$val{'password'}",20),"</th></tr>\n";
-
- print "<tr><th align=left>Baud rate:</th><th align=left>",
- &select('speed',$val{'speed'},
- '2400','9600','14400','19200','28800', '38400'),"</th></tr>";
-
- print "</table></center><br>";
-
- print &js_buttons('doadd','Ok','onClick="markAdd()"','onClick="markOther()"');
-
- print "</form></body></html>";
- }
-
- sub getAccounts {
- $i = 0;
- open(IN,"< $conf");
- while(<IN>) {
- $line = $_;
- if ($line =~ /^\s*\#/) { next; }
- $line =~ /^\s*(.*)$/;
- $line1 = $1;
- @items = split(/\s+/,$line1);
- if ($items[2] eq "ACU") {
- $nme[$i] = $items[0];
- $speed[$i] = $items[3];
- $phone[$i] = $items[4];
- for ($j=5;$j<$#items;$j++) {
- if (substr($items[$j],length($items[$j])-3,3) eq 'in:')
- { $login[$i] = $items[$j+1]; }
- if (substr($items[$j],length($items[$j])-3,3) eq 'rd:')
- { $password[$i] = $items[$j+1]; }
- }
- $i++;
- }
- }
- $number = $i;
- close(IN);
- }
-
-
- sub generic {
- &js_title_block($title, $js_main);
- &header_block($title);
-
- if (!$number && !$message) { $message = "No existing modem accounts."; }
- print "<i>$message</i>";
-
- print "<form name=AccountForm action=$myname method=post onSubmit=\"return runSubmit()\">\n";
-
- if($_[0]) { print "<input type=hidden name=toDelete value=$_[0]>\n"; }
-
- if ($number) {
- print "<h3>List of modem accounts:</h3><center>";
-
- print "<table cellpadding=5 width=450>\n";
-
- print qq|<tr><th align=left><input type=submit name="add"
- value="Add New Account" onClick="markAdd()">
- </th><td align=left><input name="nme" value="$val{'nme'}" size=19>
- </td></tr>|;
-
- print "<tr><th align=left>";
- print qq|<input type=submit name="edit"
- value="Edit Selected Account" onClick="markEdit()"></th>
- |;
-
- print "<td rowspan=2 align=left>";
- undef @locList;
- for ($i=0;$i<$number;$i++) {
- if ($nme[$i] ne $_[0]) { push(@locList,$nme[$i]); }
- }
- print &choice_list(*locList,"chosen",20);
-
- print "</td></tr>";
-
- print qq|<tr><th align=left><input type=submit name="delete"
- value="Delete Selected Account" onClick="markDelete()">
- </th></tr>|;
-
- print "</table></center><br>\n";
-
- } else {
- print "<center><table cellpadding=5 width=450>\n";
- print qq|<tr><th align=left><input type=submit name="add"
- value="Add New Account" onClick="markAdd()"> </th><td align=left>
- <input name="nme" value="$val{'nme'}" size=19> </td></tr>|;
- print "</table></center><br>";
- }
-
- print &js_buttons('doit','Ok','onClick="markOther()"','onClick="markOther()"');
-
- print "</form></body></html>";
- }
-
-